﻿#region 程序集引用
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
#endregion

#region 版权注释
/*===========================================================================
// Copyright (C) 2017 Zhang.cn，并保留所有 
// 作者：吴岸标 QQ:405403610
// 创建日期：2017-09-03
// 功能描述： 内容显示格式化
===========================================================================*/
#endregion

namespace Zhang
{
    namespace Utils
    {
        /// <summary>
        /// 内容显示格式化
        /// </summary>
        public class UI
        {
            /// <summary>
            /// 用户名显示隐藏
            /// </summary>
            /// <param name="mail">邮箱</param>
            /// <param name="mobile">手机号码</param>
            public static string UserName(string mail,string mobile)
            {
                return string.IsNullOrEmpty(mail) && mail.Trim() == "" ? mobile.Substring(0, 3) + "***" + mobile.Substring(9,2) : mail.Substring(0, 3) + "***@" + mail.Split(new string[] { "@" }, StringSplitOptions.None)[1];
            }

            /// <summary>
            /// 用户名显示隐藏
            /// </summary>
            /// <param name="mail">邮箱</param>
            public static string Mail(string mail)
            {
                if (mail.Contains("@") && mail.Length > 4)
                {
                    return mail.Substring(0, 3) + "***@" + mail.Split(new string[] { "@" }, StringSplitOptions.None)[1];
                }
                else
                {
                    return mail;
                }
            }

            /// <summary>
            /// 手机号码显示隐藏
            /// </summary>
            /// <param name="mobile">手机号码</param>
            public static string Mobile( string mobile)
            {
                if (!string.IsNullOrEmpty(mobile))
                {
                    mobile = mobile.Trim();

                    if (mobile.Length == 11)
                    {
                        mobile = mobile.Substring(0, 3) + "***" + mobile.Substring(9, 2);
                    }
                }

                return mobile;
            }

            /// <summary>
            /// 电话号码显示隐藏
            /// </summary>
            /// <param name="phone">电话号码</param>
            public static string Phone( string phone)
            {
                if (!string.IsNullOrEmpty(phone))
                {
                    phone = phone.Trim();

                    if (phone.Length > 5)
                    {
                        phone = phone.Substring(0, phone.Length - 4) + "***" + phone.Substring(phone.Length - 1);
                    }
                }

                return phone;
            }

           /// <summary>
            /// 格式化装修公司名称
           /// </summary>
           /// <param name="title">公司名称</param>
           /// <param name="city">所在城市（二级）</param>
           /// <returns></returns>
            public static string CompressDecorataionName(string title,string city)
            {
                title = title.Replace(city, "");
                title = title.Replace(city.Replace("市","").Replace("自治州","").Replace("地区",""), "");
                title = title.Replace("设计工程有限公司", "");
                title = title.Replace("设计工程有限责任公司", "");
                title = title.Replace("工程有限公司", "");
                title = title.Replace("设计有限公司", "");
                title = title.Replace("设计有限责任公司", "");
                title = title.Replace("工程有限责任公司", "");
                title = title.Replace("有限责任公司", "");
                title = title.Replace("有限公司", "");
                title = title.Replace("分公司", "");
                title = title.Replace("运营中心", "");
                title = title.Replace("材料经营部", "");
                title = Regex.Replace(title, @".*区", "");
                 return title;
            }

        }
    }
}
